package com.zzf.concurrent.example.design.pattern.active.object;

/**
 * 代理对象，负责创建MethodRequest
 * @author GaoFeng2017
 * @date 2019/9/11 14:45
 */
class ActiveObjectProxy implements ActiveObject {

    private final SchedulerThread schedulerThread;
    private final Servant servant;

    ActiveObjectProxy(SchedulerThread schedulerThread, Servant servant) {
        this.schedulerThread = schedulerThread;
        this.servant = servant;
    }

    @Override
    public Result makeString(int count, char ch) {
        FutureResult futureResult = new FutureResult();
        MakeStringRequest request = new MakeStringRequest(servant, futureResult, count, ch);
        schedulerThread.putRequest(request);
        return futureResult;
    }

    @Override
    public void printString(String text) {
        PrintStringRequest printStringRequest = new PrintStringRequest(servant, text);
        schedulerThread.putRequest(printStringRequest);
    }
}
